﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JBT.Library.Utilities;

namespace Generator.Tools
{
    public partial class ReadString : Form
    {

        public ReadString()
        {
            InitializeComponent();
            this.FormClosed += new FormClosedEventHandler(ReadString_FormClosed);
        }

        void ReadString_FormClosed(object sender, FormClosedEventArgs e)
        {
            //if (imeProvider != null)
            //{
            //    imeProvider.Dispose();
            //    imeProvider = null;
            //}
        }

        private void toolStripDropDownButton1_SelectedIndexChanged(object sender, EventArgs e)
        {
            showReadString();
        }

        private void showReadString()
        {
            timer1.Stop();

            using (MSIMEProvider imeProvider = new MSIMEProvider())
            {
                MSIME ime = (MSIME)Enum.Parse(typeof(MSIME), toolStripDropDownButton1.SelectedItem.ToString());
                var result = imeProvider.GetReadString(richTextBox1.Text, ime);
                richTextBox2.Text = result;
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            timer1.Stop();
            timer1.Start();
        }

        private void ReadString_Load(object sender, EventArgs e)
        {
            toolStripDropDownButton1.SelectedIndex = 0;
            timer1.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            showReadString();
        }
    }
}
